layui.define(['index', 'form', 'table', 'laypage', 'layedit', 'laydate', '$http', 'zmnUtils', 'layer', 'zmnSelect', 'element'], function (exports) {
    let $http = layui.$http;
    let form = layui.form;
    let zmnUtils = layui.zmnUtils;
    // 点击取消
    $("button#cancel").click(function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);//关闭当前页
    });

    // 表单校验规则
    form.verify({
        reworkLimit: function (value, item) {
            if (value !== "" && value !== '0') {
                if (Number(value) < 0) {
                    return '最大返修单量不能小于0';
                }
                if (Number(value) > 1000000) {
                    return '最大返修单量不能大于1000000';
                }
                var r = /^[1-9]\d*$/;
                if (!r.test(value)) {
                    return '只能输入正整数，请重新输入';
                }
            }
        },
        reworkReminderLimit: function (value, item) {
            if (value !== "" && value !== '0') {
                if (Number(value) < 0) {
                    return '最大返修催单单量不能小于0';
                }
                if (Number(value) > 1000000) {
                    return '最大返修催单单量不能大于1000000';
                }
                var r = /^[1-9]\d*$/;
                if (!r.test(value)) {
                    return '只能输入正整数，请重新输入';
                }
            }
        }
    });

    form.on('submit(zmn-form-submit-to-database)', function (obj) {
        let data = obj.field;
        let url = "/conf/distribute/plat/reworkReminder/modify";
        let keyIds = data.distributePlatIds.split(',');
        const dio = [];
        keyIds.forEach((value) => {
            dio.push({
                distributePlatId: value,
                reworkLimit: data.reworkLimit,
                reworkReminderLimit: data.reworkReminderLimit
            });
        })

        $http.save(url, dio).then(function () {
            zmnUtils.layui.toastSuccess('成功', function () {
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
                window.parent.location.reload();
            })
        }, function (msg) {
            zmnUtils.layui.toastError(msg);
        });

        return false;
    });

    //对外暴露的接口
    exports('oms_conf_distribute_batchEdit', {});
})